// 装修店铺
<template>
     <div class="search">
    <Row>
      <Col>
        <Card>
          <Row class="operation">
            <Form inline :label-width="100" ref="searchForm" :model="searchForm" label-position="right">

              <Form-item label="入驻类型" prop="storeType">
                <Select v-model="searchForm.storeType" style="width:150%">
                  <Option value=1>个人入驻</Option>
                  <Option value=2>商家用户</Option>
                </Select>
              </Form-item>
              <FormItem label="用户名" prop="username">
                <Input type="text" v-model="searchForm.username"/>
              </FormItem>
               <FormItem label="店铺名称" prop="shopName">
                <Input type="text" v-model="searchForm.shopName"/>
              </FormItem>
              <!-- <FormItem> -->
                <Button @click="handleSearch" type="primary" icon="ios-search" style="margin-left:20px;">搜索</Button>
            </Form>
          </Row>
            <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
         <Modal title="修改店铺" v-model="modalVisible" :mask-closable='false' :width="700">
             <Form ref="formadd" :model="formadd" :label-width="100" >
                <FormItem label="店铺名称" prop="shopName">
                  <Input type="text" v-model="formadd.shopName"/>
              </FormItem>
              <FormItem label="地址" prop="address">
                <Input v-model="formadd.address" />
             </FormItem>
              <FormItem label="手机号码" prop="mobile">
                <Input v-model="formadd.mobile" autocomplete="off"/>
             </FormItem>
             <FormItem label="图片" prop="pic">
                <upload-pic-input v-model="formadd.pic" style="width:100%"></upload-pic-input>
            </FormItem>
            <!-- <FormItem label="经度" prop="longitude">
                 <Input v-model="formadd.longitude" />
            </FormItem>
             <FormItem label="纬度" prop="latitude">
                 <Input v-model="formadd.latitude" />
             </FormItem> -->
             </Form>
             <div slot="footer">
        <Button type="text" @click="modalVisible=false">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交</Button>
      </div>
          </Modal>
      </Col>
    </Row>
    </div>
</template>

<script>
import uploadPicThumb from "@/views/my-components/xboot/upload-pic-thumb";
import uploadPicInput from "@/views/my-components/xboot/upload-pic-input";
export default {
     components: {
    uploadPicInput,
    uploadPicThumb
  },
    data(){
        return{
            data:[],
            modalVisible:false,
            total:0,
           loading: true, // 表单加载状态
           submitLoading:false,
           searchForm:{
          pageNumber:1,
          pageSize:10,
        },
         searchForm:{
          pageNumber:1,
          pageSize:10,
          username:'',
          shopName:'',
          storeType:'',
        },
        formadd:{
           id:'',
           address:'',
           mobile:'',
           shopName:'',
           pic:'',
        },
            columns: [
        // 表头
        {
          type: "index",
          width: 60,
          align: "center"
        },
        {
          title: "图片",
          key: "pic",
          minWidth: 120,
          sortable: false,
          render: (h, params) => {
            return h("avatar", {
              props: {
                src: params.row.pic
              }
            });
          }
          
        },
         {
          title: "店铺类型",
          key: "storeType",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "商家名称",
          key: "username",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "店铺名称",
          key: "shopName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "手机号码",
          key: "mobile",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "地址",
          key: "address",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          minWidth: 150,
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                    icon: "ios-create-outline",
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(params.row);
                    }
                  }
                },
                "编辑"
              ),
            ]);
          }
        }
            ],
        }
    },
    methods:{
      init(){
        this.getDataList()
      },
      //获取店铺列表
      getDataList(){
          this.loading = true;
          this.postRequest("/goodsPackage/getShopDateList",this.searchForm).then(res =>{
            this.loading = false;
              console.log(res)
              if(res.success){
                this.data = res.result.data
              } else {
                this.data = []
              }
          })
      },
      edit(v){
          console.log(v)
          this.formadd.id = v.id
          this.formadd.address = v.address
          this.formadd.mobile = v.mobile
          this.formadd.shopName = v.shopName
          this.formadd.pic = v.pic
          this.modalVisible = true
      },
      //修改
      handleSubmit(){
          console.log(this.formadd)
         this.submitLoading = true
         this.postRequest("/goodsPackage/UpdateShopParticulars",this.formadd).then(res =>{
             console.log(res)
             if(res.success){
                 this.submitLoading = false
                 this.$Message.success("修改成功")
                 this.modalVisible = false
                 this.getDataList()
             }
         })
      },
      handleSearch(){
         this.getDataList()
      },
      changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    //   this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    },
    mounted(){
       this.init() 
    }
}
</script>

<style lang="less" scoped>
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>